/**
 * Description:
 * Class Name:Test
 * Date:2022/1/25 14:37
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第5章_面向对象_上.多态.第5_9.初始化块.类初始化块;

class Root{
    static {
        System.out.println("Root static init");
    }
    {
        System.out.println("Root init");
    }
    public Root(){
        System.out.println("Root Constructor without args");
    }
}

class Mid extends Root{
    static {
        System.out.println("Mid static init");
    }
    public Mid(){
        System.out.println("Mid init");
    }
    public Mid(String msg){
        // 通过this调用同一类中重载的构造器，还记得使用this调用另一个重载构造器只能在构造器中使用，且必须作为第一条吗？
        this();
        System.out.println("Mid Construtor with String args: " + msg);
    }
}

class Leaf extends Mid{
    static {
        System.out.println("Leaf static init");
    }
    {
        System.out.println("Leaf init");
    }
    public Leaf(){
        super("Leaf ref parent-class Mid's constructor");
    }
}

public class Test {
    public static void main(String[] args) {
        new Leaf();
        new Leaf();
    }
}
